package com.wanxi.servlet;

import com.wanxi.model.BrandModel;
import com.wanxi.service.BrandService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delete")
public class BrandDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.得到前端的值
        String id = req.getParameter("id");
//        3.封装model
        BrandModel model= BrandModel.builder()
                .id(Tool.strToInt(id))
                .build();
//        4.调用服务逻辑层
        BrandService brandService=new BrandService();
       int count= brandService.delete(model);
//       5.响应给前端
        resp.sendRedirect("/findAll");
    }
}
